#!/bin/bash

if [ ! -e /mindoc/conf/app.conf ]; then
  cp /mindoc/app.conf /mindoc/conf
fi

if [ -n "$DB_HOST" ]; then
    sed -i "s/db_host=127.0.0.1/db_host=$DB_HOST/" /mindoc/conf/app.conf
fi

if [ -n "$DB_PORT" ]; then
    sed -i "s/db_port=3306/db_port=$DB_PORT/" /mindoc/conf/app.conf
fi

if [ -n "$DB_DATABASE" ]; then
    sed -i "s/db_database=mindoc_db/db_database=$DB_DATABASE/" /mindoc/conf/app.conf
fi

if [ -n "$DB_USERNAME" ]; then
    sed -i "s/db_username=root/db_username=$DB_USERNAME/" /mindoc/conf/app.conf
fi

if [ -n "$DB_PASSWORD" ]; then
    sed -i "s/db_password=123456/db_password=$DB_PASSWORD/" /mindoc/conf/app.conf
fi


sed -i "s/httpport = 8181/httpport=80/" /mindoc/conf/app.conf

/mindoc/mindoc_linux_amd64 install
/mindoc/mindoc_linux_amd64